package com.ruoyi.web.controller.shaketicket;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.shaketicket.domain.ShaketicketCoupon;
import com.ruoyi.shaketicket.service.IShaketicketCouponService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.base.AjaxResult;

/**
 * 摇一摇卡券 信息操作处理
 * 
 * @author lzy
 * @date 2019-03-01
 */
@Controller
@RequestMapping("/shaketicket/shaketicketCoupon")
public class ShaketicketCouponController extends BaseController
{
    private String prefix = "shaketicket/shaketicketCoupon";
	
	@Autowired
	private IShaketicketCouponService shaketicketCouponService;
	
	@RequiresPermissions("shaketicket:shaketicketCoupon:view")
	@GetMapping()
	public String shaketicketCoupon()
	{
	    return prefix + "/shaketicketCoupon";
	}
	
	/**
	 * 查询摇一摇卡券列表
	 */
	@RequiresPermissions("shaketicket:shaketicketCoupon:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ShaketicketCoupon shaketicketCoupon)
	{
		startPage();
        List<ShaketicketCoupon> list = shaketicketCouponService.selectShaketicketCouponList(shaketicketCoupon);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出摇一摇卡券列表
	 */
	@RequiresPermissions("shaketicket:shaketicketCoupon:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ShaketicketCoupon shaketicketCoupon)
    {
    	List<ShaketicketCoupon> list = shaketicketCouponService.selectShaketicketCouponList(shaketicketCoupon);
        ExcelUtil<ShaketicketCoupon> util = new ExcelUtil<ShaketicketCoupon>(ShaketicketCoupon.class);
        return util.exportExcel(list, "shaketicketCoupon");
    }
	
	/**
	 * 新增摇一摇卡券
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存摇一摇卡券
	 */
	@RequiresPermissions("shaketicket:shaketicketCoupon:add")
	@Log(title = "摇一摇卡券", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ShaketicketCoupon shaketicketCoupon)
	{		
		return toAjax(shaketicketCouponService.insertShaketicketCoupon(shaketicketCoupon));
	}

	/**
	 * 修改摇一摇卡券
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		ShaketicketCoupon shaketicketCoupon = shaketicketCouponService.selectShaketicketCouponById(id);
		mmap.put("shaketicketCoupon", shaketicketCoupon);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存摇一摇卡券
	 */
	@RequiresPermissions("shaketicket:shaketicketCoupon:edit")
	@Log(title = "摇一摇卡券", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ShaketicketCoupon shaketicketCoupon)
	{		
		return toAjax(shaketicketCouponService.updateShaketicketCoupon(shaketicketCoupon));
	}
	
	/**
	 * 删除摇一摇卡券
	 */
	@RequiresPermissions("shaketicket:shaketicketCoupon:remove")
	@Log(title = "摇一摇卡券", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(shaketicketCouponService.deleteShaketicketCouponByIds(ids));
	}
	
}
